/*
*    Qizx/open 3.0 beta
*
* This code is the open-source version of Qizx.
* Copyright (C) 2004-2009 Axyana Software -- All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License 
*  Version 1.1 (the "License"); you may not use this file except in 
*  compliance with the License. You may obtain a copy of the License at
*  http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
*  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
*  for the specific language governing rights and limitations under the
*  License.
*
* The Initial Developer of the Original Code is Xavier Franc - Axyana Software.
*
*/
using System;
using EvaluationException = System.Qizx.Api.EvaluationException;
using XQItem = System.Qizx.XQuery.XQItem;
using XQValue = System.Qizx.XQuery.XQValue;
namespace System.Qizx.XQuery.Dt
{
	
	/// <summary> Used by the reverse function.</summary>
	public class ReverseArraySequence:ArraySequence
	{
		public ReverseArraySequence(XQValue value_Renamed):base(8, value_Renamed)
		{
			for (; value_Renamed.Next(); )
				addItem(value_Renamed.Item);
			pack();
			reset();
		}
		
		protected internal ReverseArraySequence(System.Object[] items, int size, XQValue origin):base(size, items, origin)
		{
			reset();
		}
		
		public override XQValue BornAgain()
		{
			return new ReverseArraySequence(items, size, origin);
		}
		
		public override bool Next()
		{
			if (--index < 0)
				return false;
			item = (XQItem) items[index];
			return true;
		}
		
		public override void  reset()
		{
			index = size;
		}
		
		public override XQItem QuickIndex(long index)
		{
			return index <= 0 || index > size?null:(XQItem) items[size - (int) index];
		}
	}
}